<?php
// +----------------------------------------------------------------------
// | ZGUAN [ 致力于帮助更多的中小企业实现低成本数字化转型 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.zguan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ZGUAN 并不是自由软件，未经许可不能去掉ZGUAN 相关版权
// +----------------------------------------------------------------------
// | Author: ZGUAN Team <admin@zguan.cn>  0769-82282996  15899929162
// +----------------------------------------------------------------------
namespace app\controller\api;

class Base extends \app\controller\Base
{

    /**
     * 获取分页参数
     * @param $defaultPage
     * @param $defaultLimit
     * @return array
     *
     * @author Amos
     * 2024-05-18 09:15
     */
    protected function getPage($defaultPage = 1, $defaultLimit = 10)
    {
        $page = $this->request->get('page', $defaultPage, 'intval');
        $pageSize = $this->request->get('limit', $defaultLimit, 'intval');

        return [$page, $pageSize];
    }

    /**
     * 成功返回
     *
     * @param $data
     * @param string $message
     * @return mixed
     */
    protected function success($data = null, string $message = 'ok')
    {
        return app('api_return')->success($data, $message);
    }

    /**
     * 成功文字返回
     *
     * @param string $message
     * @return mixed
     */
    protected function successText(string $message = 'ok')
    {
        return app('api_return')->success([], $message);
    }

    /**
     * 错误返回
     *
     * @param string $message
     * @param int $code
     * @return mixed
     */
    protected function error(string $message = '', int $code = 500)
    {
        return app('api_return')->error($message, $code);
    }
}